import FontAwesome from 'react-native-vector-icons/FontAwesome';
import {AroIcon} from './AroIconfont';
import React, {Component} from 'react';
import PropTypes from 'prop-types';

const iconMap = {
    fontAwesome: FontAwesome,
    aroIcon: AroIcon
};

class Icon extends Component{
    render() {
        const{name, size, color} = this.props;
        if(!name.includes('|')){
            throw new Error('Name Parse Error!');
            return null;
        }
        let icon_name = name.split('|');
        let font_lib = icon_name[0];
        let font = icon_name[1];
        let CustomIcon = iconMap[font_lib];
        if(!CustomIcon)
            throw new Error('Can not match font lib!');
        return(
            <CustomIcon name={font} size={size} color={color} />
        )
    }
}

Icon.propTypes = {
    name: PropTypes.string.isRequired,
    size: PropTypes.number.isRequired,
    color: PropTypes.string.isRequired
};

export {Icon}
